package com.example.testgame.sprite;

import com.example.testgame.sys.Constant;
import com.example.testgame.sys.Variable;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class MapSprite extends BaseSprite {
	
	private Context ctx;
	
	private MapBlock[][] mapBlocks;
	
	private Paint mapPaint;
	private Rect mapRect;
	
	public MapSprite(Context ctx) {
		this.ctx = ctx;
		mapPaint = new Paint();
		mapRect = new Rect();
	}
	
	public void setMapData(MapBlock[][] mapBlocks) {
		this.mapBlocks = mapBlocks;
	}

	@Override
	public void draw(Canvas c) {
		if(mapBlocks == null) 
			return;
		for (int i = 0; i < mapBlocks.length; i++) {
			for (int j = 0; j < mapBlocks[i].length; j++) {
				int width = (int) (Constant.BLOCK_WIDTH * Variable.zoom);
				int height = (int) (Constant.BLOCK_HEIGHT * Variable.zoom);
				int x = (int) (j * width + Variable.offsetX);
				int y = (int) (i * height + Variable.offsetY);
				mapRect.set(x, y, x + width, y + height);
				c.drawBitmap(MapBlock.getImage(ctx, mapBlocks[i][j].type), null, mapRect, mapPaint);
			}
		}
	}

}
